﻿var arrEducation = [['', '不限'], ['1', '初中'], ['2', '中技'], ['3', '高中'], ['4', '中专'], ['5', '大专'], ['7', '本科'], ['9', '硕士'], ['11', 'MBA'], ['13', 'EMBA'], ['15', '博士'], ['0', '其它']];
var arrWorkYear = [['', '不限'], ['0', '无经验'], ['1', '1年'], ['2', '2年'], ['3', '3年'], ['4', '4年'], ['5', '5年'], ['6', '6年'], ['7', '7年'], ['8', '8年'], ['9', '9年'], ['10', '10年'], ['11', '11年'], ['12', '12年'], ['13', '13年'], ['14', '14年'], ['15', '15年'], ['16', '16年'], ['17', '17年'], ['18', '18年'], ['19', '19年'], ['20', '20年'], ['21', '21年'], ['22', '22年'], ['23', '23年'], ['24', '24年'], ['25', '25年'], ['26', '26年'], ['27', '27年'], ['28', '28年'], ['29', '29年'], ['30', '30年']];
var arrSex = [['', '不限'], ['1', '男'], ['2', '女']];
var arrWorkingOverseas = [['', '不限'], ['0', '无'], ['1', '有']];
var arrManagemenExperience = [['', '不限'], ['1', '有'], ['0', '无']];

var arrCareetStatus = [['1', '0', '离职'], ['2', '0', '在职，可一个月内到岗'], ['3', '0', '在职，不想换工作'], ['4', '0', '在职考虑换工作'], ['5', '0', '应届毕业生']];
var arrNewUpDate = [['1,9', '0', '最近三天'], ['2,9', '0', '最近一周'], ['3,9', '0', '最近二周'], ['4,9', '0', '最近一个月'], ['5,9', '0', '最近两个月'], ['6,9', '0', '最近三个月'], ['7,9', '0', '最近六个月'], ['8,9', '0', '最近一年']];

$(document).ready(function () {
    //文本框提示显示
    placeholder();

    //年龄区间的交互初始化
    ageNumberInit();
    if ($.browser.msie && $.browser.version <= "7.0") {
        $(".rd-popinput").click(function () {
            $(".rd-resume-input").css("z-index", 70);
            $(this).parent().css("z-index", 80);
        });
    }
});

//提示placeholder设置
function placeholder() {
    var elPlaceHolder = $('input[placeholder]');
    elPlaceHolder.each(function () {
        var el = $(this);
        var valPlaceHolder = el.attr('placeholder');
        if ($.trim(el.val()) === "" || $.trim(el.val()) === valPlaceHolder) {
            el.val(valPlaceHolder).css("color", "#999");
        }
        el.blur(function () {
            if ($.trim(el.val()) === "" || el.val() === valPlaceHolder) {
                el.val(valPlaceHolder).css("color", "#999");
            }
        }).focus(function () {
            if ($.trim(el.val()) === valPlaceHolder) {
                el.val('');
            }
            el.css("color", "#333");
        });
    });
}
function setInputNumber(el) {
    var value = $.trim(el.val());
    var regx = /^[0-9]*[1-9][0-9]*$/;
    if (!regx.test(value)) {
        el.val('');
    }
    else if (value < 16) {
        el.val('16');
    }
    else if (value > 100) {
        el.val('100');
    }
    el.val($.trim(el.val()));
}

//限制只能输入数字的文本框中只能是0-100的整数
function checkInputnumber() {
    var numberInput = $('input[data-type="number"]');
    numberInput.each(function () {
        var el = $(this);
        setInputNumber(el);
    });
}

//修改为年龄区间的交互行为
function ageNumberInit() {
    var numberInput = $('input[data-type="number"]');
    var ageMaxVal = $("#SF_1_1_8_max").val();
    if (ageMaxVal == "99" || ageMaxVal == "100") { $("#SF_1_1_8_max").val("") }
    numberInput.each(function () {
        var el = $(this);
        el.blur(function () {
            setInputNumber(el);
            exchangeAgeParam();
        });
    });
}
//如果年龄区间前值小于后值，交换两个值
function exchangeAgeParam() {
    var minAge = $.trim($("#SF_1_1_8_min").val());
    var maxAge = $.trim($("#SF_1_1_8_max").val());
    var regx = /^[0-9]*[1-9][0-9]*$/
    if (regx.test(minAge) && regx.test(maxAge)) {
        if (parseInt(maxAge) < parseInt(minAge)) {
            $("#SF_1_1_8_min").val(maxAge);
            $("#SF_1_1_8_max").val(minAge);
        }
    }
    if (regx.test(maxAge) && (minAge == null || minAge == "")) {
        $("#SF_1_1_8_min").val('16');
    }
}

$("#SF_1_1_8_min").live('keyup', function () {
    var value = $.trim($(this).val());
    var regx = /^[0-9]*[1-9][0-9]*$/;
    if (regx.test(value) && value.length == 2) {
        $("#SF_1_1_8_max").focus();
    }
    ;
});

//向期望地区控件赋值显示地区名称
function setCity(cityId, inputElement) {
    for (var i = 0; i < arrCity.length; i++) {
        if (arrCity[i][0] === cityId) {
            inputElement.val(arrCity[i][2]);
            inputElement[0].title = arrCity[i][2];
        }
    }
}

//加载成对Select中的上限值的选择列表
function loadMaxSelect(o, dataAarrN, value) {
    //下限制的select的选择索引
    var j = $('#' + o + '_min')[0].selectedIndex;
    var maxSelect = $('#' + o + "_max");
    maxSelect.empty();
    var selValue = dataAarrN[j][0];
    if (selValue === '') {
        maxSelect.append("<option value='" + dataAarrN[0][0] + "'>" + dataAarrN[0][1] + "</option>");
    }
    else {
        var obj = "";
        var isSelected = false;
        for (; j < dataAarrN.length; j++) {
            if (dataAarrN[j][0] === value && value !== "") {
                obj = "<option value='" + dataAarrN[j][0] + "' selected>" + dataAarrN[j][1] + "</option>";
                isSelected = true;
            }
            else {
                obj = "<option value='" + dataAarrN[j][0] + "'>" + dataAarrN[j][1] + "</option>";
            }
            $(obj).appendTo(maxSelect);
        }
        if (dataAarrN.length == 12) {
            if (selValue !== "0") {
                obj = "<option value='16' " + (isSelected ? "" : "selected") + ">及以上</option>";
            }
            $('#' + o + "_max option[value='0']").remove();
        }
        else if (dataAarrN.length == 32) {
            obj = "<option value='99'" + (isSelected ? "" : "selected") + ">及以上</option>";
        }
        if (obj !== '') {
            $(obj).appendTo(maxSelect);
        }
    }
}
/*
加载成对Select
o代表控件标识
dataAarrN代表控件的数据源
value代表默认选择的值
*/
function lib_select(o, dataAarrN, value) {
    var array = value.split(',');
    var first = '', second = '';
    if (array.length > 0) first = array[0];
    if (array.length > 1) second = array[1];

    var minSelect = $('#' + o + "_min");
    minSelect.empty();
    for (i = 0; i < dataAarrN.length; i++) {
        var obj = "<option value='" + dataAarrN[i][0] + "'>" + dataAarrN[i][1] + "</option>";
        if (dataAarrN[i][0] === first || dataAarrN[i][0] === value) {
            obj = "<option value='" + dataAarrN[i][0] + "' selected>" + dataAarrN[i][1] + "</option>";
        }
        $(obj).appendTo(minSelect);
    }

    loadMaxSelect(o, dataAarrN, second);

    minSelect.change(function () {
        loadMaxSelect(o, dataAarrN, '');
    });
}
/*
初始化radio列表
o代表控件标识
dataAarrN代表控件的数据源
value代表默认选择的值
*/
function lib_radio(o, dataArrN, value) {
    var divObj = $('#div_' + o);
    divObj.nextAll().remove();
    var divParent = divObj.parent();
    divParent.append("<span class='resumes-result-span-add'>&nbsp;</span>");
    var j = 0;
    for (i = 0; i < dataArrN.length; i++) {
        var obj = "<div class='rd-radio'><input id='" + o + "_" + i + "' name='" + o + "' value='" + dataArrN[i][0] + "' type='radio' /><label for='" + o + "_" + i + "'><span class='rd-checkbox-span'>" + dataArrN[i][1] + "</span></label></div>";
        if (value === dataArrN[i][0]) { j = i; }
        $(obj).appendTo(divParent);
    }
    $('#' + o + "_" + j).attr("checked", "checked");
}
/*
加载单个下拉框数据
*/
function lib_singleSelect(o, dataAarrN, value) {
    var minId = $('#' + o);
    minId.empty();
    minId.append("<option value='' selected>不限</option>");
    for (i = 0; i < dataAarrN.length; i++) {
        var obj = "<option value='" + dataAarrN[i][0] + "'>" + dataAarrN[i][2] + "</option>";
        if (dataAarrN[i][0] === value) {
            obj = "<option value='" + dataAarrN[i][0] + "' selected>" + dataAarrN[i][2] + "</option>";
        }
        $(obj).appendTo(minId);
    }
}

//----------------------common----------------------------//

//设置永久cookie
function setForeverCookie(key, value) {
    var date = new Date();
    date.setTime(date.getTime() + (60 * 365 * 24 * 60 * 60 * 1000));
    $.cookie(key, value, { path: '/', expires: date });
}

//设置会话cookie
function setTempCookie(key, value) {
    $.cookie(key, value, { path: '/', expires: null });
}

//删除指定cookie
function removeCookie(key) {
    var date = new Date();
    date.setTime(date.getTime() + (-1 * 24 * 60 * 60 * 1000));
    $.cookie(key, null, { path: '/', expires: date });
}

//字符串长度截取
function cutstr(str, len) {
    var str_length = 0;
    var str_len = 0;
    str_cut = new String();
    str_len = str.length;
    for (var i = 0; i < str_len; i++) {
        a = str.charAt(i);
        str_length++;
        if (escape(a).length > 4) {
            //中文字符的长度经编码之后大于4
            str_length++;
        }
        str_cut = str_cut.concat(a);
        if (str_length >= len) {
            str_cut = str_cut.concat("...");
            return str_cut;
        }
    }
    //如果给定字符串小于指定长度，则返回源字符串；
    if (str_length < len) {
        return str;
    }
}

//打开新页面
function openFeedback(strTarget) {
    window.open(strTarget, "_blank", 'width=1,height=1,left=100,top=60, scrollbars=0, overflow=auto, status=0');
}

//通过query页面跳转
function jumpNewPage(query) {
    getJump(window.location.pathname + query.toString());
}

//登录退出
function openLogout() {
    getJump("http://rd2.zhaopin.com/s/loginmgr/logout.asp");
}

//跳转页面
function getJump(url) {
    if (getIEVersion() > 0) {
        var tempa = document.createElement("a");
        tempa.href = url;
        document.getElementsByTagName("body")[0].appendChild(tempa);
        tempa.click();
    }
    else {
        window.location.href = url;
    }
}

//获取IE版本
function getIEVersion() {
    var rv = -1;
    if (navigator.appName === "Microsoft Internet Explorer") {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[/.0-9]{0,})");
        if (re.exec(ua) !== null) {
            rv = parseFloat(RegExp.$1);
        }
    }
    return rv;
}